from rest_framework import serializers

from course.models import CourseGroup, Course, RotationMap, PdfManage
from utils.common.common import datetime_format


class CourseGroupSerializer(serializers.ModelSerializer):

    class Meta:
        model = CourseGroup
        fields = '__all__'


class CourseSerializer(serializers.ModelSerializer):

    class Meta:
        model = Course
        fields = '__all__'

    def to_representation(self, instance):
        data = super().to_representation(instance)
        data["group_name"] = instance.course_group.group_name
        return data


class RotationMapSerializer(serializers.ModelSerializer):

    class Meta:
        model = RotationMap
        fields = '__all__'


class PdfManageSerializer(serializers.ModelSerializer):

    class Meta:
        model = PdfManage
        fields = '__all__'

    def to_representation(self, instance):
        data = super().to_representation(instance)
        data["create_time"] = datetime_format(data["create_time"])
        data["update_time"] = datetime_format(data["update_time"])
        return data
